home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / misc.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  1KB  |  64 lines

  1. /* Miscellaneous machine independent utilities */
  2.  
  3. #include "global.h"
  4. #include <ctype.h>
  5. #ifdef    UNIX
  6. #undef    toupper
  7. #undef    tolower
  8. #endif
  9.  
  10. /* Convert hex-ascii to integer */
  11. int
  12. htoi(s)
  13. char *s;
  14. {
  15.     int i = 0;
  16.     char c;
  17.  
  18.     while((c = *s++) != '\0'){
  19.         if(c == 'x')
  20.             continue;    /* allow 0x notation */
  21.         if('0' <= c && c <= '9')
  22.             i = (i * 16) + (c - '0');
  23.         else if('a' <= c && c <= 'f')
  24.             i = (i * 16) + (c - 'a' + 10);
  25.         else if('A' <= c && c <= 'F')
  26.             i = (i * 16) + (c - 'A' + 10);
  27.         else
  28.             break;
  29.     }
  30.     return i;
  31. }
  32. /* replace terminating end of line marker(s) with null */
  33. rip(s)
  34. register char *s;
  35. {
  36.     register char *cp;
  37.  
  38.     if((cp = index(s,'\r')) != NULLCHAR)
  39.         *cp = '\0';
  40.     if((cp = index(s,'\n')) != NULLCHAR)
  41.         *cp = '\0';
  42. }
  43. /* Case-insensitive string comparison */
  44. strncasecmp(a,b,n)
  45. register char *a,*b;
  46. register int n;
  47. {
  48.     char a1,b1;
  49.  
  50.     while(n-- != 0 && (a1 = *a++) != '\0' && (b1 = *b++) != '\0'){
  51.         if(a1 == b1)
  52.             continue;    /* No need to convert */
  53.         a1 = tolower(a1);
  54.         b1 = tolower(b1);
  55.         if(a1 == b1)
  56.             continue;    /* NOW they match! */
  57.         if(a1 > b1)
  58.             return 1;
  59.         if(a1 < b1)
  60.             return -1;
  61.     }
  62.     return 0;
  63. }
  64.